/**
 * 
 */
package ua.kiev.ntukpi.asu.ga.gui;

import java.awt.geom.Ellipse2D;
import java.util.ArrayList;
import java.util.List;

import ua.kiev.ntukpi.asu.ga.Individual;

/**
 * @author Alexander Galibey
 *
 */
public class PairsHolder {

	private List<Individual> indList = new ArrayList<Individual>();
	
	private List<Ellipse2D> elList = new ArrayList<Ellipse2D>();
	
	public synchronized List<Ellipse2D> getAll(List<Individual> individuals){
		
		List<Ellipse2D> result = new ArrayList<Ellipse2D>();
		for (Individual individual : individuals){
			
			int indexOf = indList.indexOf(individual);
			if (indexOf >=0 && (elList.size()> indexOf)){
				
				result.add(elList.get(indexOf));
			}
		}
		return result;
	}
	
	public synchronized void add(Individual individual){
		
		this.add(individual, new Ellipse2D.Double());
	}
	
	public synchronized void add(Individual individual, Ellipse2D ellipse2D){
		
		this.indList.add(individual);
		this.elList.add(ellipse2D);
	}
	
	public synchronized void removeAll(List<Individual> individuals){
		
		List<Ellipse2D> foundEllList = getAll(individuals);
		this.elList.removeAll(foundEllList);
		this.indList.removeAll(individuals);
		
	}
	
	public synchronized void addAll(List<Individual> individuals){
		
		for (Individual individual : individuals){
			
			add(individual);
		}
	}
	
	public synchronized void addAll(List<Individual> individuals, List<Ellipse2D> ellList){
		
		for (int i = 0; i < individuals.size(); i++){
			
			add(individuals.get(i), ellList.get(i));
		}
	}

	public synchronized List<Individual> getIndividuals() {
		return indList;
	}

	public synchronized List<Ellipse2D> getElList() {
		return elList;
	}
	
	public synchronized Individual getIndividual(Ellipse2D ellipse2D){
		
		return indList.get(elList.indexOf(ellipse2D));
	}

	public synchronized void clear(){
		
		this.elList.clear();
		this.indList.clear();
	}
}
